package com.sharemarking.system.service.impl;

import com.sharemarking.system.dto.UserDetailImpl;
import com.sharemarking.system.mapper.PermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import java.io.Serializable;

@Service
public class PermissionEvaluatorImpl implements PermissionEvaluator {
	
	@Autowired
	private PermissionMapper pm;
	
	@Override
	public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
		Integer targetPermission=pm.getIdByDomainAndName((String)targetDomainObject,(String)permission);
		UserDetailImpl udi=(UserDetailImpl)authentication.getPrincipal();
		System.out.println(udi.getPermissions());
		System.out.println(targetPermission);
		return udi.getPermissions().contains(targetPermission);
	}
	/**
	 * 数据权限与项目需求相关，此处不作处理
	 */
	@Override
	public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType,
			Object permission) {
		// TODO Auto-generated method stub
		return false;
	}

}
